﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SqlClient;

namespace SoundServant
{
    /// <summary>
    /// Interaction logic for LoadWindow.xaml
    /// </summary>
    public partial class ChangePasswordWindow : SSWindow
    {
        Congregation congregation;

        public ChangePasswordWindow(Congregation _congregation)
        {
            InitializeComponent();
            congregation = _congregation;

        }

        public static new void Show(Congregation _cong)
        {
            ChangePasswordWindow changePasswordWindow = new ChangePasswordWindow(_cong);
            changePasswordWindow.ShowDialog();
        }

        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            if (OldPasswordTouchBox.Text == congregation.Password)
            {
                if (NewPassword1TouchBox.Text == NewPassword2TouchBox.Text)
                {
                    congregation.Password = NewPassword1TouchBox.Text;
                    Logs.Information("Password", "Congregation Password Changed");
                    this.Closing -= Window_Closing;
                    this.Close();
                }
                else
                {
                    SSMessageBox.Show("Passwords Don't Match", "The new passwords you have enetered do not match. Try again!.", SSMessageBoxType.Ok);
                }
            }
            else
            {
                SSMessageBox.Show("Incorrect Password", "The old password you have entered is not correct. Try again!", SSMessageBoxType.Ok);
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.Closing -= Window_Closing;
            this.Close();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
        }


    }

}
